//
//  PathModel.m
//  RouteSearcher
//
//  Created by wenqingzhou on 2/16/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PathModel.h"


@implementation PathModel

@synthesize type,duration,dist,arrayOfPoints,tmpPoint,code,tmpStop;
-(NSString *)getPathWithString
{
	NSString *typeStr;
	switch([self.type intValue])
	{
			case 1:
			case 3:
			case 4:
			case 5:
				typeStr=@"BUS";
				break;
			case 2:
				typeStr=@"TRAM";
				break;
			case 6:
				typeStr=@"METRO";
				break;
			case 7:
				typeStr=@"FERRY";
				break;
			case 12:
				typeStr=@"TRAIN";
				break;
			case 22:
			case 25:
				typeStr=@"NIGHT BUS";
				break;
			default:
				typeStr=@"WALK";
	}
	NSLog(@"%@",typeStr);
	if(self.type==nil)
	{
		NSString *from,*to;
		if([[self.arrayOfPoints objectAtIndex:0] isKindOfClass:[PointModel class]])
		{
			from=[[self.arrayOfPoints objectAtIndex:0] uid];
		}
		else {
			from=[[self.arrayOfPoints objectAtIndex:0] name];
		}
		if([[self.arrayOfPoints objectAtIndex:1] isKindOfClass:[PointModel class]])
		{
			to=[[self.arrayOfPoints objectAtIndex:1] uid];
		}
		else {
			to=[[self.arrayOfPoints objectAtIndex:1] name];
		}
		NSLog(@"from:%@,to:%@",from,to);
		return [typeStr stringByAppendingFormat:@",from %@(%@) to %@(%@),duration:%dminutes, distance:%fkm",
				from,
				[[self.arrayOfPoints objectAtIndex:0] arriveTime],
				to,
				[[self.arrayOfPoints objectAtIndex:1] arriveTime],
				self.duration,
				self.dist];
	}
	else {
		NSLog(@"from:%@,to:%@",[[self.arrayOfPoints objectAtIndex:0] name],[[self.arrayOfPoints lastObject] name]);
		return [typeStr stringByAppendingFormat:@" %@,from %@(%@) to %@(%@),duration:%dminutes, distance:%fkm",
				self.code,
				[[self.arrayOfPoints objectAtIndex:0] name],
				[[self.arrayOfPoints objectAtIndex:0] arriveTime],
				[[self.arrayOfPoints lastObject] name],
				[[self.arrayOfPoints lastObject] arriveTime],
				self.duration,
				self.dist];
	}

}

- (void)dealloc
{
	[self.arrayOfPoints release];
	[self.tmpPoint release];
	[self.tmpStop release];
	[self.code release];
	[self.type release];
	[self.dist release];
	[super dealloc];
}

@end
